<!--
* @description 巡检计划详情
* @author zywu
* @date 2021/03/04 09:49:48
!-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="dataForm.name+'详情'"
    width="600px"
    top="10vh"
    :visible.sync="visible"
    v-dialogDrag
  >
    <el-form label-width="120px" :model="dataForm" ref="dataForm" style="padding-right:20px;">
      <el-form-item label="巡检标签：">
        <el-tag disable-transitions>{{dataForm.labelName}}</el-tag>
      </el-form-item>
      <el-form-item label="责任主体：">{{dataForm.lliableName}}</el-form-item>
      <el-form-item label="包含点位：">
        <div style="min-height:46px;">
          <el-tag
            v-for="(item) in pointList"
            :key="item.id"
            effect="plain"
            disable-transitions
            style="margin:0 10px 10px 0;"
          >{{item.name}}</el-tag>
        </div>
        <p v-if="orgCount>1" style="color:red;">注意：点位分布在{{orgCount}}个单位。</p>
      </el-form-item>
      <el-form-item label="开始结束日期：">{{dataForm.startTimeStr}}&nbsp;~&nbsp;{{dataForm.endTimeStr||'一直持续'}}</el-form-item>
      <el-form-item label="巡检频率：">{{['','一天一次','一天多次','一周一次','一月一次','一季度一次'][dataForm.examineRate||0]}}</el-form-item>
      <el-form-item v-if="rule">
        <el-card class="box-card">
          <template v-if="dataForm.examineRate==2">
            <p
              v-for="(item,i) in rule.workTime||[]"
              :key="i"
            >{{'第'+(i+1)+'次巡检：'}}{{item.startIsNextday?'次日':''}}{{item.startTime.substr(0,5)}}&nbsp;~&nbsp;{{item.endIsNextday?'次日':''}}{{item.endTime}}</p>
            <p>{{(rule.workday.split(',')).map(n=>{ return '周'+numbers[n-1] }).join('，')}}</p>
          </template>
          <template v-else-if="dataForm.examineRate==1">
            <p>开始时间：{{rule.startTime.substr(0,5)}}</p>
            <p>结束时间：{{rule.endIsNextday?'次日':''}}{{rule.endTime}}</p>
            <p>{{(rule.workday.split(',')).map(n=>{ return '周'+numbers[n-1] }).join('，')}}</p>
          </template>
          <template v-else-if="dataForm.examineRate==3">
            <p>开始时间：周一{{rule.startTime.substr(0,5)}}</p>
            <p>结束时间：周{{numbers[rule.endDay-1]}}{{rule.endTime}}</p>
          </template>
          <template v-else-if="dataForm.examineRate==4">
            <p>开始时间：月初{{rule.startTime.substr(0,5)}}</p>
            <p>结束时间：月末{{rule.endTime}}</p>
          </template>
          <template v-else-if="dataForm.examineRate==5">
            <p>开始时间：季度第一天{{rule.startTime.substr(0,5)}}</p>
            <p>结束时间：季度最后一天{{rule.endTime}}</p>
            <p>限定按自然季度计算</p>
          </template>
        </el-card>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import util from '@/utils/util'
import { getPointListOfPlan } from '@/api/inspectx'
export default {
  data() {
    return {
      visible: false,
      numbers: ['一', '二', '三', '四', '五', '六', '日'],
      dataForm: {},
      rule: {
        endDay: 1,
      },
      orgCount: 0,
      pointList: [],
    }
  },

  methods: {
    init(data) {
      this.visible = true
      this.orgCount = 0
      this.pointList = []
      data.startTimeStr = util.ilinkTimeformat.format(
        new Date(data.startTime),
        'yyyy-MM-dd'
      )
      if (data.endTime) {
        data.endTimeStr = util.ilinkTimeformat.format(
          new Date(data.endTime),
          'yyyy-MM-dd'
        )
      }
      this.dataForm = Object.assign({}, data)
      this.rule = JSON.parse(data.rule)
      getPointListOfPlan({ ids: data.planPointsId }).then((res) => {
        this.pointList = res.data
        if (this.pointList.length > 1) {
          this.orgCount = Array.from(
            new Set(
              this.pointList.map((n) => {
                return n.orgId
              })
            )
          ).length
        }
      })
    },
  },
}
</script>
<style lang='scss'>
</style>